<?php
set_time_limit(0);
mysql_connect('localhost', 'root', '123456');
mysql_select_db('newjerseysoccer');
$sql = 'select * from zcshop_attachments';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
    getImg($row['attachment_url']);
    getImg($row['cut_url']);
    getImg($row['medium_img']);
}

$sql = 'select * from zcshop_products';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
        getImg($row['cut_url']);
        getImg($row['medium_url']);
}

$sql = 'select * from zcshop_productfls';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
        getImg($row['logostr']);
}

$sql = 'select * from zcshop_badge';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
        $arr = explode('|', $row['img']);
    foreach ($arr as $v) {
        getImg($v);
    }
}

$sql = 'select * from zcshop_lagnappe_attachments';
while($row = mysql_fetch_array($result)) {
        getImg($row['cut_url']);
        getImg($row['attachment_url']);
}


function getImg($file)
{
    if (!$file) {
        return;
    }
    $root = '.';
    $tmpImg = explode('?', $file);
    $arr = pathinfo($tmpImg[0]);
    $dirName = $root . '/' . $arr['dirname'];
    if (!file_exists($dirName)) {
        mkdir($dirName, 0777, true);
    }
    if (!file_exists($root . '/' . $file)) {
        $content = file_get_contents('http://www.elmontyouthsoccer.com/' . $file);
        @file_put_contents($root . '/' . $file,$content);

        echo $file . "\r\n";
    }
    return;

}